package com.qsq.newsmanager.service.impl;

import com.qsq.newsmanager.dao.NewsDao;
import com.qsq.newsmanager.dto.InsertExcution;
import com.qsq.newsmanager.entity.News;
import com.qsq.newsmanager.enums.InsertStatEnum;
import com.qsq.newsmanager.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lining on 2017/3/28.
 */
@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsDao newsDao;

    // 插入一条新闻记录
    public InsertExcution insertNews(News news) {
        int insertCount = newsDao.insertNews(news);
        if (insertCount == 1) {
            return new InsertExcution(news.getNewsId(), InsertStatEnum.SUCCESS);
        } else {
            return new InsertExcution(InsertStatEnum.FAULT);
        }
    }

    // 根据新闻ID查询对应记录
    public News queryById(long newsId) {
        return newsDao.queryById(newsId);
    }

    // 查询所有新闻记录
    public List<News> queryAll() {
        return newsDao.queryAll();
    }
}
